package apiServer

import (
	"autoTestNew/pkg/config"
	"fmt"
	"github.com/gin-gonic/gin"
	"go.uber.org/fx"
	"net"
)

var (
	Module = fx.Options(
		fx.Provide(
			newEngine,
			newAPIRouter,
		),
		handlerModule,

		fx.Invoke(register),
	)
)

func register(r *gin.Engine, conf *config.ChaosDashboardConfig) {
	listenAddr := net.JoinHostPort(conf.ListenHost, fmt.Sprintf("%d", conf.ListenPort))

	go r.Run(listenAddr)
}
func newEngine(config *config.ChaosDashboardConfig) *gin.Engine {
	r := gin.Default()

	return r
}

func newAPIRouter(r *gin.Engine) *gin.RouterGroup {
	api := r.Group("/api")

	// FIXME 暂时移除 swagger
	//api.GET("/swagger/*any", swaggerserver.Handler)
	return api
}
